package huawei.widget;

import android.content.Context;
import android.content.res.ColorStateList;
import android.content.res.Resources;
import android.content.res.Resources.Theme;
import android.content.res.TypedArray;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.LayerDrawable;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View.OnClickListener;
import android.widget.LinearLayout;
import android.widget.TextView;
import o.fo;
import o.fqd.a;
import o.fqd.b;
import o.fqd.c;
import o.fqd.d;
import o.fqd.e;
import o.fqd.g;
import o.fqd.i;
import o.fqd.j;
import o.gg;

public class HwDownloadBar extends LinearLayout {
    private LinearLayout ʻ;
    private int ʼ;
    private int ʽ;
    private HwDownLoadWidget ˊ;
    private ColorStateList ˊॱ;
    private HwButton ˋ;
    private int ˋॱ;
    private TextView ˎ;
    private HwButton ˏ;
    private ColorStateList ˏॱ;
    private ColorStateList ͺ;
    private TextView ॱ;
    private ColorStateList ॱˊ;
    private LinearLayout ॱॱ;
    private LinearLayout ᐝ;

    public HwDownloadBar(Context context) {
        this(context, null);
    }

    public HwDownloadBar(Context context, AttributeSet attributeSet) {
        this(context, attributeSet, 0);
    }

    public HwDownloadBar(Context context, AttributeSet attributeSet, int i) {
        super(context, attributeSet, i);
        ˏ(context, attributeSet);
    }

    private void ˏ(Context context, AttributeSet attributeSet) {
        LayoutInflater.from(getContext()).inflate(j.ˊ, this, true);
        this.ॱ = (TextView) findViewById(d.ॱॱ);
        this.ˎ = (TextView) findViewById(d.ʻ);
        this.ˏ = (HwButton) findViewById(d.ˎ);
        this.ˋ = (HwButton) findViewById(d.ᐝ);
        this.ˊ = (HwDownLoadWidget) findViewById(d.ˊ);
        this.ᐝ = (LinearLayout) findViewById(d.ॱ);
        this.ʻ = (LinearLayout) findViewById(d.ʼ);
        this.ॱॱ = (LinearLayout) findViewById(d.ʽ);
        this.ˋॱ = getResources().getDimensionPixelSize(e.ˋ);
        this.ʽ = getResources().getDimensionPixelSize(e.ˎ);
        Drawable ˊ = fo.ˊ(context, c.ˎ);
        Drawable ˊ2 = fo.ˊ(context, c.ˊ);
        Drawable ˊ3 = fo.ˊ(context, c.ˎ);
        gg.ॱ(gg.ʻ(ˊ2).mutate(), fo.ˋ(context, a.ˋ));
        Drawable layerDrawable = new LayerDrawable(new Drawable[]{ˊ2, ˊ});
        ˊ = new LayerDrawable(new Drawable[]{ˊ2, ˊ3});
        this.ˏ.setBackground(layerDrawable);
        this.ˋ.setBackground(ˊ);
        Theme theme = context.getTheme();
        if (theme != null) {
            TypedArray obtainStyledAttributes = theme.obtainStyledAttributes(attributeSet, i.ˊˋ, b.ˊ, g.ˎ);
            if (obtainStyledAttributes != null) {
                this.ͺ = obtainStyledAttributes.getColorStateList(i.ˋˊ);
                this.ˏॱ = obtainStyledAttributes.getColorStateList(i.ˊᐝ);
                obtainStyledAttributes.recycle();
            }
        }
        setStyleMode(0);
    }

    private void ˎ(LinearLayout linearLayout, TextView textView, Drawable drawable, CharSequence charSequence) {
        if (textView == null || linearLayout == null) {
            Log.w("DownloadBar", "DownloadBar item layout initialization failed");
            return;
        }
        textView.setText(charSequence);
        if (drawable != null || ˎ(textView)) {
            Drawable mutate;
            if (drawable != null) {
                float f;
                int intrinsicWidth = drawable.getIntrinsicWidth();
                int intrinsicHeight = drawable.getIntrinsicHeight();
                if (intrinsicWidth > this.ʽ) {
                    f = ((float) this.ʽ) / ((float) intrinsicWidth);
                    intrinsicWidth = this.ʽ;
                    intrinsicHeight = (int) (((float) intrinsicHeight) * f);
                }
                if (intrinsicHeight > this.ʽ) {
                    f = ((float) this.ʽ) / ((float) intrinsicHeight);
                    intrinsicHeight = this.ʽ;
                    intrinsicWidth = (int) (((float) intrinsicWidth) * f);
                }
                drawable.setBounds(0, 0, intrinsicWidth, intrinsicHeight);
            }
            if (ˎ(textView)) {
                textView.setBackground(null);
                textView.setCompoundDrawables(null, drawable, null, null);
            } else {
                textView.setCompoundDrawables(null, null, null, null);
                textView.setBackground(drawable);
            }
            ColorStateList ˊ = ˊ();
            ColorStateList ॱ = ॱ();
            if (drawable != null) {
                mutate = gg.ʻ(drawable).mutate();
            } else {
                mutate = null;
            }
            if (ˊ == null || ॱ == null) {
                if (!(this.ˏॱ == null || mutate == null)) {
                    gg.ॱ(mutate, this.ˏॱ);
                }
                if (this.ͺ != null) {
                    textView.setTextColor(this.ͺ);
                    return;
                }
                return;
            }
            if (mutate != null) {
                gg.ॱ(mutate, ˊ);
            }
            textView.setTextColor(ॱ);
            return;
        }
        linearLayout.setVisibility(8);
    }

    public void setSmartIconColor(ColorStateList colorStateList) {
        this.ˊॱ = colorStateList;
    }

    public void setSmartTitleColor(ColorStateList colorStateList) {
        this.ॱˊ = colorStateList;
    }

    private ColorStateList ˊ() {
        return this.ˊॱ;
    }

    private ColorStateList ॱ() {
        return this.ॱˊ;
    }

    private boolean ˎ(TextView textView) {
        return !TextUtils.isEmpty(textView.getText());
    }

    public void setStyleMode(int i) {
        this.ʼ = i;
        switch (this.ʼ) {
            case 0:
                this.ᐝ.setVisibility(8);
                this.ˊ.setVisibility(0);
                return;
            case 1:
                this.ᐝ.setVisibility(0);
                this.ˊ.setVisibility(8);
                return;
            default:
                return;
        }
    }

    protected void onMeasure(int i, int i2) {
        int lineCount;
        if (this.ॱ != null) {
            lineCount = this.ॱ.getLineCount();
        } else {
            lineCount = 0;
        }
        int lineCount2;
        if (this.ˎ != null) {
            lineCount2 = this.ˎ.getLineCount();
        } else {
            lineCount2 = 0;
        }
        if (!(this.ˎ == null || this.ॱ == null)) {
            if (lineCount > 1 || r2 > 1) {
                setPadding(0, this.ˋॱ, 0, this.ˋॱ);
                this.ʻ.setGravity(49);
                this.ॱॱ.setGravity(49);
            } else {
                setPadding(0, 0, 0, 0);
                this.ʻ.setGravity(17);
                this.ॱॱ.setGravity(17);
            }
        }
        super.onMeasure(i, i2);
    }

    public void setStartItem(Drawable drawable, CharSequence charSequence) {
        ˎ(this.ʻ, this.ॱ, drawable, charSequence);
    }

    public void setStartItem(int i, int i2) {
        ˎ(this.ʻ, this.ॱ, fo.ˊ(getContext(), i), getContext().getResources().getText(i2));
    }

    public void setEndItem(Drawable drawable, CharSequence charSequence) {
        ˎ(this.ॱॱ, this.ˎ, drawable, charSequence);
    }

    public void setEndItem(int i, int i2) {
        ˎ(this.ॱॱ, this.ˎ, fo.ˊ(getContext(), i), getContext().getResources().getText(i2));
    }

    public void setStartAndEndItem(Drawable drawable, CharSequence charSequence, Drawable drawable2, CharSequence charSequence2) {
        ˎ(this.ʻ, this.ॱ, drawable, charSequence);
        ˎ(this.ॱॱ, this.ˎ, drawable2, charSequence2);
    }

    public void setStartAndEndItem(int i, int i2, int i3, int i4) {
        Resources resources = getContext().getResources();
        ˎ(this.ʻ, this.ॱ, fo.ˊ(getContext(), i), resources.getText(i2));
        ˎ(this.ॱॱ, this.ˎ, fo.ˊ(getContext(), i3), resources.getText(i4));
    }

    public void setStartItemClickListener(OnClickListener onClickListener) {
        if (this.ʻ == null) {
            Log.w("DownloadBar", "DownloadBar startItem is null");
        } else {
            this.ʻ.setOnClickListener(onClickListener);
        }
    }

    public void setEndItemClickListener(OnClickListener onClickListener) {
        if (this.ॱॱ == null) {
            Log.w("DownloadBar", "DownloadBar endItem is null");
        } else {
            this.ॱॱ.setOnClickListener(onClickListener);
        }
    }

    public void setApplyButtonClickListener(OnClickListener onClickListener) {
        if (this.ˏ == null) {
            Log.w("DownloadBar", "DownloadBar primary button is null ");
        } else {
            this.ˏ.setOnClickListener(onClickListener);
        }
    }

    public void setUpdateButtonClickListener(OnClickListener onClickListener) {
        if (this.ˋ == null) {
            Log.w("DownloadBar", "DownloadBar primary button is null ");
        } else {
            this.ˋ.setOnClickListener(onClickListener);
        }
    }

    public void setButtonsText(CharSequence charSequence, CharSequence charSequence2) {
        ˋ(charSequence, this.ˏ);
        ˋ(charSequence2, this.ˋ);
    }

    public void setButtonsText(int i, int i2) {
        ˋ(getContext().getResources().getText(i), this.ˏ);
        ˋ(getContext().getResources().getText(i2), this.ˋ);
    }

    private void ˋ(CharSequence charSequence, HwButton hwButton) {
        if (hwButton == null) {
            Log.w("DownloadBar", "DownloadBar button layout initialization failed");
        } else {
            hwButton.setText(charSequence);
        }
    }
}
